﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

/// <summary>
/// Summary description for FailedAuthenticationManager
/// </summary>
public class FailedAuthenticationManager {
	public const int MAX_RETRIES = 3;

	protected static FailedAuthenticationManager instance;

	protected Dictionary<User, int> userMap;

	private FailedAuthenticationManager() {
		this.userMap = new Dictionary<User, int>();
	}

	public static FailedAuthenticationManager GetInstance() {
		if (FailedAuthenticationManager.instance == null) {
			FailedAuthenticationManager.instance = new FailedAuthenticationManager();
		}
		return FailedAuthenticationManager.instance;
	}

	public void reset(User user) {
		this.userMap[user] = 0;
	}

	public bool increment(User user) {
		if (!this.userMap.Keys.Contains(user)) {
			this.userMap[user] = 0;
		}
		this.userMap[user]++;
		bool result = false;
		if (this.userMap[user] > FailedAuthenticationManager.MAX_RETRIES) {
			result = true;
		}
		return result;
	}
}
